import flash.utils.Dictionary;

class Properties  {
	
	var _props:Dictionary;
	var _parent:Properties;
	
	public function new(json:Dynamic, parent:Properties=null)
	{
		this._props = new Dictionary();
		this._parent = parent;
		
		// trace(json);
		
		for (prop in json ) {
			
			// trace( prop +' = ' + json[prop]);
			this._props[prop] = json[prop];
		}
	}

	public function get(name:String):Float {
		
		if ( this._props[name] != null )
			return this._props[name];
		
		if ( this._parent != null )
			return this._parent.get( name );
			
		
		//trace( 'ERROR: property not found', name); // TODO - port this to haxe trace (MyTrace)
		return Math.NEGATIVE_INFINITY;
	}


	// set does not recurse down, we don't want to set
	// our parents property
	public function set(name:String, value:Dynamic):Void {
		this._props[name] = value;	
	}

	/// NOTE: This got eaten by the shitty "as3 to haxe" converter written in haskell
	public function has(name:String):Bool
	{
		if (this._props[name] != null)
			return true;
		
		if (this._parent != null)
			return this._parent.has(name);

		return false;
	}
}
